#include<bits/stdc++.h>
using namespace std;

int n,m;
string num;
int u=0;
string ans;
map<char,int> a={
	{'0',0},{'1',1},{'2',2},{'3',3},
	{'4',4},{'5',5},{'6',6},{'7',7},
	{'8',8},{'9',9},{'A',10},{'B',11},
	{'C',12},{'D',13},{'E',14},{'F',15}
};
char b[18]={
'0','1','2','3',
'4','5','6','7',
'8','9','A','B',
'C','D','E','F'
};
int main(){
	cin>>n;
	cin>>num;
	int size=num.size();
	for(int i=0;i<size;i++){
		u*=n;
		u+=a[num[i]];
	}
	cin>>m;
	while(u){
		int v=u%m;
		u/=m;
		ans=b[v]+ans;
	}
	cout<<ans;
	return 0;
}
